Designing Distributed Systems: Patterns and Paradigms for Scalable, Reliable Systems Using Kubernetes by Brendan Burns

Designing Distributed Systems: Patterns and Paradigms for Scalable, Reliable Systems Using Kubernetes by Brendan Burns

Author:Brendan Burns [Burns, Brendan]
Language: eng
Format: epub
Tags: Computers, Software Development & Engineering, General, Distributed Systems, Cloud Computing
ISBN: 9781098156350
Google: 9zjK0AEACAAJ
Publisher: O'Reilly Media
Published: 2024-12-30T23:00:00+00:00


The Basics of Leader Election

Imagine that there is a service Foo with three replicas: Foo-1, Foo-2, and Foo-3. There is also some object Bar that must only be “owned” by one of the replicas (e.g., Foo-1) at a time. Often this replica is called the leader, hence the term leader election used to describe the process of how this leader is selected as well as how a new leader is selected if that leader fails.

There are two ways to implement this leader election. This first is to implement a distributed consensus algorithm like Paxos or RAFT, but the complexity of these algorithms make them beyond the scope of this book and not worthwhile to implement. Implementing one of these algorithms is akin to implementing locks on top of assembly code compare-and-swap instructions. It’s an interesting exercise for an undergraduate computer science course, but it is not something that is generally worth doing in practice.

Fortunately, there are a large number of distributed key-value stores that have implemented such consensus algorithms for you. At a general level, these systems provide a replicated, reliable data store and the primitives necessary to build more complicated locking and election abstractions on top. Examples of these distributed stores include etcd, ZooKeeper, and Consul. The basic primitives that these systems provide is the ability to perform a compare-and-swap operation for a particular key. Compare-and-swap atomically writes a new value if the existing value matches the expected value. If the value doesn’t match, it returns false. If the value doesn’t exist and currentValue is not null, it returns an error. If you haven’t seen compare-and-swap before, it is basically an atomic operation that looks like this:

lock := sync.Mutex{} store := map[string]string{} func compareAndSwap(key, nextValue, currentValue string) (bool, error) { lock.Lock() defer lock.Unlock() _, containsKey := store[key] if !containsKey { if len(currentValue) == 0 { store[key] = nextValue return true, nil } return false, fmt.Errorf( "Expected value %s for key %s, but found empty", currentValue, key) } if store[key] == currentValue { store[key] = nextValue return true, nil } return false, nil }

In addition to compare-and-swap, the key-value stores allow you to set a time-to-live (TTL) for a key. Once the TTL expires, the key is set back to empty.

Put together, these functions are sufficient to implement a variety of distributed synchronization primitives.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Popular ebooks
In-Memory Analytics with Apache Arrow by Matthew Topol(2693)
Data Forecasting and Segmentation Using Microsoft Excel by Fernando Roque(2690)
PostgreSQL 14 Administration Cookbook by Simon Riggs(2217)
Cloud Auditing Best Practices: Perform Security and IT Audits across AWS, Azure, and GCP by building effective cloud auditing plans by Shinesa Cambric Michael Ratemo(1609)
Architects of Intelligence_The Truth About AI From the People Building It by Martin Ford(1237)
In-Memory Analytics with Apache Arrow: Perform fast and efficient data analytics on both flat and hierarchical structured data by Matthew Topol(1035)
Mastering Azure Virtual Desktop: The Ultimate Guide to the Implementation and Management of Azure Virtual Desktop by Ryan Mangan(1012)
Automated Machine Learning in Action by Qingquan Song Haifeng Jin Xia Hu(900)
Python GUI Programming with Tkinter, 2nd edition by Alan D. Moore(869)
Ansible for Real-Life Automation - A complete Ansible handbook filled with practical IT automation use cases (2022) by Packt(740)
Learn Wireshark - A definitive guide to expertly analyzing protocols and troubleshooting networks using Wireshark - 2nd Edition (2022) by Packt(733)
Data Engineering with Scala and Spark by Eric Tome Rupam Bhattacharjee David Radford(413)
Introduction to Algorithms, Fourth Edition by unknow(360)
ABAP Development for SAP HANA by Unknown(357)
Automated Machine Learning in Action by Qingquan Song & Haifeng Jin & Xia Hu(301)
Kubernetes Secrets Handbook by Emmanouil Gkatziouras | 
Rom Adams
 | Chen Xi(283)
Asynchronous Programming in Rust by Carl Fredrik Samson;(256)
Learn Enough Developer Tools to Be Dangerous: Git Version Control, Command Line, and Text Editors Essentials by Michael Hartl(254)
Machine Learning for Imbalanced Data by Kumar Abhishek Dr. Mounir Abdelaziz(249)
The AWK Programming Language by Aho Alfred V. Kernighan Brian W. Weinberger Peter J. & Brian W. Kernighan & Peter J. Weinberger(236)